﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataModel;
using System.Data;
using System.Data.SqlClient;

namespace SchoolDataLayer
{
   public class DLFee
    {
       public int SaveBillItem(BillItem item)
       {
           using (SqlConnection conn = DBConn.GetConnectionString())
           {
               using (SqlCommand cmd = conn.CreateCommand())
               {
                   cmd.CommandText = "ProcSaveFeeItem";
                   cmd.CommandType = CommandType.StoredProcedure;
                   cmd.Parameters.AddWithValue("@FeeItem", item.billItem);
                   cmd.Parameters.AddWithValue("@billid", item.billItemId);
                   int id = cmd.ExecuteNonQuery();
                   return id;
               }
           }
       }

       public List<BillItem> GetBillItem()
       {
           List<BillItem> billItemList = new List<BillItem>();
           using (SqlConnection conn = DBConn.GetConnectionString())
           {
               using (SqlCommand cmd = conn.CreateCommand())
               {
                   cmd.CommandText = "ProcGetBillItem";
                   cmd.CommandType = CommandType.StoredProcedure;
                   SqlDataReader reader = cmd.ExecuteReader();
                   if (reader != null)
                   {
                       while (reader.Read())
                       {
                           billItemList.Add(new BillItem {
                               billItemId = (int)reader["FeeItemId"],
                               billItem = (string)reader["FeeItem"]
                           
                           });
                       
                       }
                   }
                   //int id = cmd.ExecuteNonQuery();
                   return billItemList;
               }
           }
       }
    }
}
